// Test for MLisp

#include <gtest/gtest.h>
#include "mlisp.h"
#include "mio.h"
#include "mhash.h"
#include "mstring.h"
#include "mfpnum.h"
#include "smem.h"
#include "ssym.h"
#include "senv.h"

#define	EQ(s1, s2)		EXPECT_TRUE(eq(s1, s2))


const int HEAP_SIZE = 1024 * 1024;
static unsigned long s_heap[HEAP_SIZE / sizeof(unsigned long)];

class MLispTest : public testing::Test {
protected:
	virtual void SetUp() {
		smem_init(s_heap, HEAP_SIZE, mlisp_gc);
		sexp_new();

		init_mlisp();
		define_io_module();
		define_hash_module();
		define_string_module();
		define_fpnum_module();
	}

	virtual void TearDown() {
		sexp_set_error_callback(NULL);
		term_mlisp();
		sexp_delete();
	}
};


//=============================================================================

TEST_F(MLispTest, Eval) {
	SExp r = call_func(global_variable_ref(intern("+")), 2, fixnum2s(1), fixnum2s(2));
	EQ(r, fixnum2s(3)) << "call_func";

	EQ(exec_string("(if 1 2 3)"), fixnum2s(2)) << "exec_string";
}
